package cn.santi.controller;

import cn.santi.domain.Staff;
import cn.santi.emuns.R;
import cn.santi.service.StaffService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/staff")
public class StaffController {
    @Autowired
    private StaffService ss;

    @GetMapping("/stafflogin")
    public R stafflogin(String username, String password) {
        QueryWrapper<Staff> wrapper = new QueryWrapper<>();
        wrapper.eq("phone", username).eq("password", password);
        Staff one = ss.getOne(wrapper);
        if (one != null) {
            // 检查账号状态
            if (one.getState().equals("0")) {
                return R.ok(one);
            } else {
                return R.fail(300,"账号异常");
            }
        } else {
            return R.fail("手机号或密码错误");
        }
    }
}
